package com.study.servlet;

import com.study.dao.CustomerDao;
import com.study.dao.impl.CustomerDaoImpl;
import com.study.model.Customer;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author WS
 */
@WebServlet(name = "updateSuccessCustomer",urlPatterns = "/updateSuccessCustomer")
public class CustomerUpdateSuccessServlet extends BaseServlet {
    private CustomerDao dao=new CustomerDaoImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 解决json中文乱码
        req.setCharacterEncoding("UTF-8");
        Customer update=new Customer();
        String idstr=req.getParameter("id");
        int id=Integer.parseInt(idstr);
        update.setId(id);
        update.setAddress(req.getParameter("address"));
        update.setCardNo(req.getParameter("cardno"));
        update.setCardType(req.getParameter("cardtype"));
        update.setName(req.getParameter("name"));
        update.setNickname(req.getParameter("nickname"));
        update.setPwd(req.getParameter("pwd"));
        update.setSex(req.getParameter("sex"));
        update.setTel(req.getParameter("tel"));
        update.setBirthday(req.getParameter("birthday"));
        update.setWorkUnit(req.getParameter("workunit"));
        dao.update(update);
        req.getRequestDispatcher("/index.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req,resp);
        doGet(req, resp);
    }
}
